// *** ADDED BY HEADER FIXUP ***
#include <wx/gdicmn.h>
// *** END ***
// *** ADDED BY HEADER FIXUP ***
#include <wx/colour.h>
#include <wx/utils.h>
// *** END ***
#include "AddQueryDlg.h"
#include "Mysocket.h"
//(*InternalHeaders(AddQueryDlg)
#include <wx/font.h>
#include <wx/intl.h>
#include <wx/string.h>
//*)
//(*IdInit(AddQueryDlg)
const long AddQueryDlg::ID_STATICTEXT1 = wxNewId();
const long AddQueryDlg::ID_STATICTEXT3 = wxNewId();
const long AddQueryDlg::ID_STATICTEXT2 = wxNewId();
const long AddQueryDlg::ID_CHOICE1 = wxNewId();
const long AddQueryDlg::ID_BUTTON2 = wxNewId();
const long AddQueryDlg::ID_CHECKBOX1 = wxNewId();
const long AddQueryDlg::ID_BUTTON1 = wxNewId();
//*)

BEGIN_EVENT_TABLE(AddQueryDlg,wxDialog)
	//(*EventTable(AddQueryDlg)
	//*)
END_EVENT_TABLE()

AddQueryDlg::AddQueryDlg(wxWindow* parent):
    newQueryDlg(this)
{
	BuildContent(parent);
}

void AddQueryDlg::BuildContent(wxWindow* parent)
{
	//(*Initialize(AddQueryDlg)
	wxBoxSizer* BoxSizer2;
	wxBoxSizer* BoxSizer1;

	Create(parent, wxID_ANY, _("语料库添加~"), wxDefaultPosition, wxDefaultSize, wxCAPTION|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL, _T("wxID_ANY"));
	BoxSizer1 = new wxBoxSizer(wxVERTICAL);
	StaticText1 = new wxStaticText(this, ID_STATICTEXT1, _("未识别的咨询句子！"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1"));
	StaticText1->SetForegroundColour(wxColour(255,0,0));
	wxFont StaticText1Font(10,wxSWISS,wxFONTSTYLE_NORMAL,wxBOLD,false,_T("Arial"),wxFONTENCODING_DEFAULT);
	StaticText1->SetFont(StaticText1Font);
	BoxSizer1->Add(StaticText1, 0, wxTOP|wxLEFT|wxALIGN_BOTTOM|wxALIGN_CENTER_HORIZONTAL, 5);
	lbQuery = new wxStaticText(this, ID_STATICTEXT3, _("Label"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT3"));
	lbQuery->SetForegroundColour(wxColour(0,0,255));
	wxFont lbQueryFont(12,wxSWISS,wxFONTSTYLE_NORMAL,wxNORMAL,false,wxEmptyString,wxFONTENCODING_DEFAULT);
	lbQuery->SetFont(lbQueryFont);
	BoxSizer1->Add(lbQuery, 0, wxTOP|wxLEFT|wxALIGN_BOTTOM|wxALIGN_CENTER_HORIZONTAL, 5);
	BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
	StaticText2 = new wxStaticText(this, ID_STATICTEXT2, _("请选择咨询类型："), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT2"));
	BoxSizer2->Add(StaticText2, 0, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	choice = new wxChoice(this, ID_CHOICE1, wxDefaultPosition, wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T("ID_CHOICE1"));
	BoxSizer2->Add(choice, 1, wxALL|wxEXPAND|wxALIGN_LEFT|wxALIGN_BOTTOM, 5);
	bnNewType = new wxButton(this, ID_BUTTON2, _("+"), wxDefaultPosition, wxSize(23,24), 0, wxDefaultValidator, _T("ID_BUTTON2"));
	bnNewType->SetForegroundColour(wxColour(0,128,128));
	wxFont bnNewTypeFont(12,wxSWISS,wxFONTSTYLE_NORMAL,wxBOLD,false,_T("Arial"),wxFONTENCODING_DEFAULT);
	bnNewType->SetFont(bnNewTypeFont);
	BoxSizer2->Add(bnNewType, 0, wxALL|wxALIGN_LEFT|wxALIGN_BOTTOM, 5);
	cbThat = new wxCheckBox(this, ID_CHECKBOX1, _("与上条回答相关"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX1"));
	cbThat->SetValue(false);
	BoxSizer2->Add(cbThat, 0, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	bnEnter = new wxButton(this, ID_BUTTON1, _("确定"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
	BoxSizer2->Add(bnEnter, 0, wxALL|wxALIGN_LEFT|wxALIGN_BOTTOM, 5);
	BoxSizer1->Add(BoxSizer2, 0, wxALL|wxEXPAND|wxALIGN_LEFT|wxALIGN_BOTTOM, 5);
	SetSizer(BoxSizer1);
	BoxSizer1->Fit(this);
	BoxSizer1->SetSizeHints(this);

	Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&AddQueryDlg::OnbnNewTypeClick);
	Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&AddQueryDlg::OnbnEnterClick);
	//*)
}

AddQueryDlg::~AddQueryDlg()
{
	//(*Destroy(AddQueryDlg)
	//*)
}
int AddQueryDlg::ShowModal(const wxString &query)
{
    if(choice->IsEmpty()) return wxID_CANCEL;
    if(choice->GetSelection()==wxNOT_FOUND) choice->Select(0);
	lbQuery->SetLabel(query);
	SelectThat(false);
	queryType.clear();answer.clear();
	return wxDialog::ShowModal();
}

void AddQueryDlg::AddQueryType(const wxString& type)
{
    int cnt = 0;
    for(size_t i=0;i<choice->GetCount();++i) if(choice->GetString(i)>type)
	{
		cnt = i;
		break;
	}
	choice->Insert(type,cnt);
}
void AddQueryDlg::RemoveQueryType(const wxString& type)
{
    int pos = choice->FindString(type,true);
    if(pos==wxNOT_FOUND) return;
    else choice->Delete(pos);
}

void AddQueryDlg::OnbnEnterClick(wxCommandEvent& event)
{
    queryType = choice->GetStringSelection();
    EndModal(wxID_OK);
}
bool AddQueryDlg::IsThat()
{
    return cbThat->GetValue();
}

void AddQueryDlg::SelectThat(bool opt)
{
    cbThat->SetValue(opt);
}

void AddQueryDlg::OnbnNewTypeClick(wxCommandEvent& event)
{
    if(newQueryDlg.ShowModal(lbQuery->GetLabel())==wxID_OK)
    {
        queryType = newQueryDlg.GetQueryType();
        answer = newQueryDlg.GetAnswer();
        EndModal(wxID_OK);
    }
}
